package config.ioc;

import com.dao.UserDao;
import com.dao.UserDaoImpl;
import com.service.UserService;
import com.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HelloIocConfig3 {
    //3. 因为HelloIocConfig3是被spring管理的，所以也可以进行依赖的注入
    @Autowired
    private UserDao dao;


    @Bean
    public UserService userService() {

        UserServiceImpl userService = new UserServiceImpl();
        userService.setDao(dao);
        return userService;
    }

    @Bean
    public UserDao userDao() {
        return new UserDaoImpl();
    }
}
